package thread;

import java.util.ArrayList;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        ArrayList<Integer> list = new ArrayList<>();
        Aoo a = new Aoo(list);

        Thread t1 = new Thread(){
            public void run(){
                a.start();
            }
        };

        Thread t2 = new Thread(){
            public void run(){
                a.start();
            }
        };

        t1.start();
        t2.start();

        Thread.sleep(5000);

        System.out.println(list.size());
    }
}

class Aoo{
    private ArrayList<Integer> list;
    public Aoo(ArrayList<Integer> list) {
        this.list = list;
    }

    public synchronized void start(){
        for (int i = 0; i < 10000; i++) {
            list.add(i);
        }
    }
}


